package com.honour.controller.interfaced;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.honour.service.interfaced.BootPageInManager;
import com.system.controller.base.BaseController;
import com.system.util.AppUtil;
import com.system.util.PageData;
import com.system.util.Tools;
import com.system.util.ToolsUtil;

/**  引导页接口
 @Function
 @Author zhaozhenhua
 @Date   2017年11月22日
*/
@Controller
@RequestMapping(value="/appbootpagein")
public class BootPageInController extends BaseController{
	
	@Resource(name="bootpageinService")
	private BootPageInManager bootpageinService;
	
	/**
	 * 获得引导页列表接口
	 * @Author zhaozhenhua
	 * @date   2017年11月22日
	 * @return
	 */
	@RequestMapping(value="/bootpagelist")
	@ResponseBody
	public Object getBootPageList(){
		logBefore(logger, "获得引导页列表接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("BOOTPAGELIST", pd.getString("FKEY"))){	//检验请求key值是否合法
				List<PageData> list = bootpageinService.listAll(pd);
					if (list.size()!=0) {
						 map.put("pd", list);
					}
					//返回01为查询成功并返回,02为查询为空
					result = (0 == list.size()) ?  "02" :  "01";
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	
	/**
	 * 选择卡种类的图片接口
	 * @Author 于泓磊
	 * @date   2017年12月14日
	 * @return
	 */
	@RequestMapping(value="/getcardimgs")
	@ResponseBody
	public Object getCardImgs(){
		logBefore(logger, "选择卡种类的图片接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("CARDIMGS", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("cardImgs", pd)){	//检查参数
				 pd = bootpageinService.getCardImgs(pd);
				 ToolsUtil.putImgstoArray(pd, "CARDIMGS");
				 map.put("pd", pd);
					//返回01为查询成功并返回,02为查询为空
					result = (null == pd) ?  "02" :  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 分类随机显示6个卡号接口
	 * @Author 于泓磊
	 * @date   2017年12月14日
	 * @return
	 */
	@RequestMapping(value="/getcardnum")
	@ResponseBody
	public Object getCardNum(){
		logBefore(logger, "分类随机显示6个卡号接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("CARDNUM", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("cardImgs", pd)){	//检查参数
				 List<PageData> list = bootpageinService.getCardNumList(pd);
				 if (list.size()!=0) {
					 map.put("pd", list);
				}
					//返回01为查询成功并返回,02为查询为空
					result = (0 == list.size()) ?  "02" :  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 分类随机显示12个卡号接口
	 * @Author 于泓磊
	 * @date   2018年1月3日
	 * @return
	 */
	@RequestMapping(value="/getcardnumweb")
	@ResponseBody
	public synchronized Object getCardNumWeb(){
		logBefore(logger, "分类随机显示12个卡号接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("CARDNUM", pd.getString("FKEY"))){	//检验请求key值是否合法
				 List<PageData> list = bootpageinService.getCardNumListWeb(pd);
				 if (list.size()!=0) {
					 map.put("pd", list);
					 
				}
					//返回01为查询成功并返回,02为查询为空
					result = (0 == list.size()) ?  "02" :  "01";
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		System.out.println(pd.get("callback")+"("+new Gson().toJson(AppUtil.returnObject(pd,map))+")");
		return pd.get("callback")+"("+new Gson().toJson(AppUtil.returnObject(pd,map))+")";
	}
	
	/**
	 * 全部分类随机显示12个卡号接口
	 * @Author 于泓磊
	 * @date   2018年1月3日
	 * @return
	 */
	@RequestMapping(value="/getcardnumallweb")
	@ResponseBody
	public synchronized Object getCardNumAllWeb(){
		logBefore(logger, "全部分类随机显示12个卡号接口");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("CARDNUM", pd.getString("FKEY"))){	//检验请求key值是否合法
				for (int i = 1; i < 6; i++) {
					pd.put("CARDTYPE_ID", i);
					 List<PageData> list = bootpageinService.getCardNumListWeb(pd);
					 if (list.size()!=0) {
						 pd.put("list"+i, list);
					}
				}
				
				map.put("pd", pd);
				//返回01为查询成功并返回,02为查询为空
				result = (0 == pd.size()) ?  "02" :  "01";
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		System.out.println(pd.get("callback")+"("+new Gson().toJson(AppUtil.returnObject(pd,map))+")");
		return pd.get("callback")+"("+new Gson().toJson(AppUtil.returnObject(pd,map))+")";
	}
	
}
